package com.juzipi.demo.controller;


import com.juzipi.demo.constant.ResultCode;
import com.juzipi.demo.service.UsersService;
import com.juzipi.demo.tools.json.ResultTool;
import com.juzipi.demo.utils.StringUtils;
import com.juzipi.demo.utils.json.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    private UsersService usersService;


    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    @GetMapping("user")
    public Result getAllUsers(){
        List<Users> users = usersService.queryAllUsers();
        if (StringUtils.isEmpty(users)){
            return ResultTool.fail();
        }
        return ResultTool.successCustomize(ResultCode.QUERY_SUCCESSFULLY,users);
    }


    @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
    @GetMapping("test")
    public Result test(){
        return ResultTool.successCustomize(ResultCode.QUERY_SUCCESSFULLY,"你好呀");
    }


    @PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
    @GetMapping("test1")
    public Result test1(){
        return ResultTool.successCustomize(ResultCode.QUERY_SUCCESSFULLY,"你好吗");
    }



    @GetMapping("test2")
    public Result test2(){
        return ResultTool.successCustomize(ResultCode.QUERY_SUCCESSFULLY,"你还好吗？");
    }

}
